package number_operatation.leetcode.medium;

/**
 * @author bruin_du
 * @description 数组中数字出现的次数
 * @date 2022/6/5 17:17
 **/
public class Offer56I_SingleNumbers {
    public int[] singleNumbers(int[] nums) {
        int n = 0,a = 1,x1 = 0,x2 = 0;
        for (int num : nums) {
            n ^= num;
        }
        while((a & n) == 0) a <<= 1;
        for (int num : nums) {
            if((a & num) != 0){
                x1 ^= num;
            }else{
                x2 ^= num;
            }
        }
        return new int[]{x1,x2};
    }
}
